<?php

/*
 * FileName AppViews.php
 * Date		2012-8-14
 * Author	jime
 * Mail 	me@joyphper.net
 * QQ		97142822
 * Copyright (C) 2012 joyphper.net
 */
if (!defined('App_PATH'))
	exit ('request error');

class AppViews {

	private $data = array (); //传送模板中的传
	private $smarty;

	//初始化smarty模板引擎
	private function initSmarty(){
		import('misc/smarty/Smarty.class.php');
		$config = C("smarty");
		$this->smarty = new Smarty;

		$this->smarty -> template_dir 	= App_PATH."/".$config['template_dir']; //模板存放目录
		$this->smarty -> compile_dir 	= App_PATH."/".$config['compile_dir']; //编译目录
		$this->smarty -> config_dir 	= App_PATH."/".$config['config_dir']; //缓存目录
		$this->smarty -> cache_dir 		= App_PATH."/".$config['cache_dir']; //缓存目录
		$this->smarty -> left_delimiter = $config['left_delimiter']; //左定界符
		$this->smarty -> right_delimiter= $config['right_delimiter']; //右定界符
		$this->smarty -> debugging 		= $config['debugging'];
		$this->smarty -> caching 		= $config['caching'];
		$this->smarty -> cache_lifetime = $config['cache_lifetime'];

	}
	//向模板内赋值
	public function assign($key,$var,$nocache=false) {
		if(empty($this->smarty)) $this->initSmarty();

		$this->smarty->assign($key, $var,$nocache);
	}

	//向展示一个模板
	public function display($tmpl) {
		if(empty($this->smarty)) $this->initSmarty();

		$this->smarty->display($tmpl);
	}
}
?>
